package com.phkj.qdh.ui.adapter

import android.content.Context
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.hjq.toast.ToastUtils
import com.phkj.qdh.R
import com.phkj.qdh.bean.CorrectiveFeedbackVOList
import com.phkj.qdh.utils.MyItemDecoration
import com.phkj.qdh.utils.gone
import com.phkj.qdh.utils.visible

class ShenPiAdapter : BaseQuickAdapter<CorrectiveFeedbackVOList, QuickViewHolder>() {


    override fun onBindViewHolder(
        holder: QuickViewHolder, position: Int, item: CorrectiveFeedbackVOList?
    ) {
        val llImage = holder.getView<LinearLayout>(R.id.ll_img)
        val tv_reson = holder.getView<TextView>(R.id.tv_reson)
        val tv_reson_name = holder.getView<TextView>(R.id.tv_reson_name)
        val tv_date = holder.getView<TextView>(R.id.tv_date)
        tv_date.text = item?.createdTime
        val rv = holder.getView<RecyclerView>(R.id.rv)
        when (item?.refuseFlag) {
            0 -> {
                //反馈
                tv_reson.text = "反馈内容:"
                tv_reson_name.text = item.feedback
                if (item?.feedbackImages.isNullOrEmpty()) {
                    rv.adapter = null
                    llImage.gone()
                } else {
                    llImage.visible()
                    val imagerViewAdapter = ImagerViewAdapter(true)
                    rv.run {
                        layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
                        adapter = imagerViewAdapter
                        addItemDecoration(
                            MyItemDecoration(
                                ContextCompat.getColor(
                                    context, R.color.transparent
                                ), 25, RecyclerView.HORIZONTAL
                            )
                        )
                    }
                    imagerViewAdapter.submitList(item?.feedbackImages)
                }

            }

            1 -> {
//                退回
                llImage.gone()
                tv_reson.text = "退回原因:"
                tv_reson_name.text = item?.refuseReason ?: ""
            }

            else -> {
                //下发
                llImage.gone()
                tv_reson_name.gone()
                tv_reson.text = "下发"
            }
        }

    }

    override fun onCreateViewHolder(
        context: Context, parent: ViewGroup, viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.item_shenpi, parent)
    }
}